<?php
include("config.php");
include("include/db_connect.php");
include("include/session.php");
include("include/common.php");
include("include/item.php");
include("include/search.php");
include("include/payment.php");

if(isset($_SESSION['user_id'])) {
	if(isset($_REQUEST['credit'])) {
		$credit = $_REQUEST['credit'];
		$amount = $credit * 0.1;
		if($credit == 500) {
			$credit = $credit + 25;
		} else 	if($credit == 1000) {
			$credit = $credit + 100;
		}
		$pay_key = buy_credits ($_SESSION['user_id'], $credit, $amount);
		if($pay_key === false ) {
			get_page("message", array("title" => "Error!", "message" => "Try again!"));
		} else {
			get_page("message", array("redirect" => "https://www.sandbox.paypal.com/webscr&cmd=_ap-payment&paykey=$pay_key"));
		}
	} else {
		get_page("message", array("redirect" => "index.php"));
	}
} else {
	get_page("message", array("redirect" => "index.php"));
}
?>
